class Solution(object):
    def distinctEchoSubstrings(self, text):
        n = len(text)
        DP = [[0] * n for _ in range(n)]
        ans = set()
        base = 10 ** 9 + 7
        for i in range(n):
            now = 0
            for j in range(i, n):
                now = (now * 26 + ord(text[j]) - ord('a')) % base
                DP[i][j] = now
        for i in range(n):
            for k in range(1, n):
                if i + 2 * k <= n:
                    if DP[i][i + k - 1] == DP[i + k][i + 2 * k - 1]:
                        ans.add(text[i: i + 2 * k])
                else:
                    break
        return len(ans)


data = Solution()
text = "abcabcabc"
print(data.distinctEchoSubstrings(text))
